package cn.bellychang.command.demo02;

import cn.bellychang.command.demo02.command.Command;
import cn.bellychang.command.demo02.command.DoNothingCommand;

import java.util.stream.IntStream;

/**
 * @author ChangLiang
 * @date 2020/4/14
 */
public class SmartControl {

    Command[] onCommands;
    Command[] offCommands;

    public SmartControl() {
        onCommands = new Command[3];
        offCommands = new Command[3];
        Command doNothingCommand = new DoNothingCommand();
        IntStream.rangeClosed(0,2).forEach((i)->{
            onCommands[i] = doNothingCommand;
            offCommands[i] = doNothingCommand;
        });
    }

    public void setCommand(int slot, Command onCommand, Command offCommand){
        onCommands[slot] = onCommand;
        offCommands[slot] = offCommand;
    }

    public void onButtonPressed(int slot) {
        onCommands[slot].execute();
    }

    public void offButtonPressed(int slot) {
        offCommands[slot].execute();
    }
}
